/**
 *
 * @param testName
 * @param description
 * @param testSet
 */
function Test( testName, description, testSet, isSetupOrTearDown )
{
    this.doInit.apply(this, arguments);
    this.name = testName;
    this.description = description ? description : '';
    this.created = toFullDateString(new Date());
    this.testTasks = new TasksList(this, "Tasks");
    this.testSet = testSet;
    this.displayValue = testName;
    this.isSetupOrTearDown = isSetupOrTearDown;
    this.deletable = !isSetupOrTearDown;
    this.upDownEnabled = !this.isSetupOrTearDown;
    



}

/**
 *
 *
 */
Test.prototype = domplate(TestFireObject,
{
    displayValue: "Tests",
    name: null,
    created: null,

    init: function()
    {
        this.displayValue = this.name;
        this.deletable = !this.isSetupOrTearDown;
        this.upDownEnabled = !this.isSetupOrTearDown;        
    },

    isUpAvailable : function()
    {
        return this._isUpAvailable(this.testSet.tests);
    },

    isDownAvailable : function()
    {
        return this._isDownAvailable(this.testSet.tests);
    },

    moveDown : function()
    {
        return this._moveDown(this.testSet.tests);
    },

    moveUp : function()
    {
        return this._moveUp(this.testSet.tests);
    },

    getChildrenToDisplay: function()
    {
        var ary = new Array();
        ary.push({name: "name", object: this.name});
        ary.push({name: "description", object: this.description});
        ary.push({name: "created", object: this.created});
        ary.push({name: "testTasks", object: this.testTasks});

        return ary;
    },

    setName : function(name)
    {
        if(this.isSetupOrTearDown)
        {
            alert("setUp and tearDown cannot be renamed.");
        }
        else{
            this.name = name;
            this.displayValue = name;
        }
    },

    deleteSelf : function()
    {
        try{
            this.testSet.deleteTest(this);
        }
        catch(ex)
        {
            Firebug.TestFire.util.tf_debug(ex);
        }
    },

    open : function(element)
    {
        var attrs = element.attributes;        
        this.copyAttributesToObject(this, attrs);
        /* setUp */
        var descEl = element.getElementsByTagName("description").item(0);
        this.description = descEl.textContent;
        this.init();
        

        /* Tasks */
        var tasks = element.getElementsByTagName("tasks").item(0);
        this.testTasks.open(tasks);

    },

    toXMLStringAry: function(overrideTagName)
    {
        if(!overrideTagName){
            overrideTagName = 'test';
        }
        var ret = [];
        ret.push('<tf:'+ overrideTagName + ' name="' + this.name + '" created="' + this.created + '" >');
        ret.push('<tf:description>' + this.description + '</tf:description>');
        ret.push('<tf:tasks>');
        ret = ret.concat(this.testTasks.toXMLStringAry());
        ret.push('</tf:tasks>');
        ret.push('</tf:'+overrideTagName+'>');

        return ret;
    },

    toString : function()
    {
        return this.displayValue;
    }


});